package com.wedo.mall.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.e.library.adapter.Adapter;
import com.wedo.mall.R;
import com.wedo.mall.activity.user.EvaluateActivity;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Lawrence on 2017/9/3.
 */

public class EvaluatePictureAdapter extends Adapter<HashMap<String, Object>> {

    private EvaluateActivity evaluateActivity;
    private List<HashMap<String, Object>> hashMaps;

    public OnEvaluateActivityListener oeaListener;

    public EvaluatePictureAdapter(Context context, List<HashMap<String, Object>> hashMaps,EvaluateActivity activity) {
        super(context, hashMaps);
        evaluateActivity = activity;
        this.hashMaps = hashMaps;
    }

    @Override
    protected int layout() {
        return R.layout.item_pictureevaluate;
    }

    @Override
    protected void bind(EHolder holder, HashMap<String, Object> stringObjectHashMap, final int position) {
        RelativeLayout rl_pictureevaluate = holder.find(R.id.rl_pictureevaluate);
        ImageView iv_delete_pictrue_id = holder.find(R.id.iv_delete_pictrue_id);
        ImageView iv_item_grida_image = holder.find(R.id.iv_item_grida_image);

        iv_item_grida_image.setVisibility(View.VISIBLE);
        iv_delete_pictrue_id.setVisibility(View.VISIBLE);
        iv_item_grida_image.setImageBitmap((Bitmap) stringObjectHashMap.get("itemImage"));
        iv_item_grida_image.setOnClickListener(null);
        iv_delete_pictrue_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hashMaps.remove(position);
                String i = evaluateActivity.mSelectedPhotos.toString();
                evaluateActivity.mSelectedPhotos.remove(position);
                //evaluateActivity.evaluatePictureAdapter.notifyDataSetChanged();
            }
        });

        if(position == hashMaps.size()-1){
            if(position > 2){
                rl_pictureevaluate.setVisibility(View.GONE);
                iv_delete_pictrue_id.setVisibility(View.GONE);
                iv_item_grida_image.setVisibility(View.GONE);
            }else{
                rl_pictureevaluate.setVisibility(View.VISIBLE);
                iv_delete_pictrue_id.setVisibility(View.GONE);
                iv_item_grida_image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        oeaListener.onPictureClick();
                    }
                });
            }
        }
    }

    /**
     * fragment回调
     */
    public interface OnEvaluateActivityListener {
        public void onPictureClick();
    }

    /**
     * 监听
     * @param Listener
     */
    public void setOnPictureClickListener (OnEvaluateActivityListener  Listener) {
        this.oeaListener = Listener;
    }
}
